package com.luber.web.controller.backstage;

import java.util.List;
import java.util.Map;

import com.luber.backstage.domain.EticketRoute;
import com.luber.backstage.domain.vo.AddEticketRouteVO;
import com.luber.backstage.domain.vo.EticketRouteVO;
import com.luber.backstage.domain.vo.UpdateEticketRouteVO;
import com.luber.backstage.service.IEticketRouteService;
import com.luber.common.core.domain.entity.SysUser;
import com.luber.common.core.domain.model.LoginUser;
import com.luber.common.utils.ServletUtils;
import com.luber.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.luber.common.annotation.Log;
import com.luber.common.core.controller.BaseController;
import com.luber.common.core.domain.AjaxResult;
import com.luber.common.enums.BusinessType;
import com.luber.common.utils.poi.ExcelUtil;
import com.luber.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author luber
 * @date 2021-01-31
 */
@RestController
@RequestMapping("/backstage/route")
public class EticketRouteController extends BaseController
{
    @Autowired
    private IEticketRouteService eticketRouteService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(EticketRoute eticketRoute)
    {
        startPage();
        List<EticketRouteVO> list = eticketRouteService.selectEticketRouteList(eticketRoute);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EticketRoute eticketRoute)
    {
        List<EticketRouteVO> list = eticketRouteService.selectEticketRouteList(eticketRoute);
        ExcelUtil<EticketRouteVO> util = new ExcelUtil<EticketRouteVO>(EticketRouteVO.class);
        return util.exportExcel(list, "route");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eticketRouteService.selectEticketRouteById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AddEticketRouteVO vo)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 用户信息
        SysUser user = loginUser.getUser();
        vo.setCreateUser(user.getUserId());
        return AjaxResult.success(eticketRouteService.add(vo));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpdateEticketRouteVO vo)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 用户信息
        SysUser user = loginUser.getUser();
        vo.setUpdateUser(user.getUserId());
        return AjaxResult.success(eticketRouteService.updateEticketRoute(vo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('backstage:route:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eticketRouteService.deleteEticketRouteByIds(ids));
    }
}
